home *** CD-ROM | disk | FTP | other *** search
/ Interactive Media Design Review 1999 / Interactive Media Design Review 1999.iso / pc / Demos / Herois / Codigo.Cst / 00012_Script_Anima Sprite < prev    next >
Text File  |  1999-03-19  |  5KB  |  150 lines

  1. property spr
  2. property memberPrim, memberUlt -- Cast members que serao animados
  3. property memPrim, memQuantos -- Membros: em numero
  4. property espera -- Tempo de espera entre cada mudanca (em ticks) 
  5. property aleatorio -- True para mudanca aleatoria
  6. property ultimaTroca -- Hora em que foi feita ultima troca
  7. property fotoAtual
  8. property tempoAleatorio
  9. property proxEspera
  10. property delta
  11. property prioridade
  12. property memoria, sorteado, removeSpr
  13. property embaralhaInk
  14.  
  15. on getBehaviorDescription
  16.   return "Anima sprites"
  17. end
  18.  
  19. on getPropertyDescriptionList
  20.   set p_list = [ ¼
  21.     #memberPrim: [ #comment:   "Primeiro membro da animacao", ¼
  22.                     #format:   #string, ¼
  23.                    #default:   "" ], ¼
  24.     #memberUlt: [ #comment:   "Ultimo membro da animacao", ¼
  25.                     #format:   #string, ¼
  26.                    #default:   "" ], ¼
  27.     #espera: [ #comment: "Espera entre cada troca em 1/60s (velocidade)",¼
  28.                       #format: #integer,¼
  29.                      #default: 60 ],¼
  30.     #aleatorio: [ #comment: "Animacao randomica",¼
  31.                       #format: #boolean,¼
  32.                      #default: false ],¼
  33.     #tempoAleatorio: [ #comment: "Tempo de animacao randomica",¼
  34.                       #format: #boolean,¼
  35.                      #default: false ],¼
  36.     #delta: [ #comment: "Espera no inicio da animacao",¼
  37.                       #format: #integer,¼
  38.                      #default: 0 ],¼
  39.     #prioridade: [ #comment: "Prioridade da animacao (se anima em momentos criticos)",¼
  40.                       #format: #integer,¼
  41.                      #default: 0 ],¼
  42.     #memoria: [ #comment: "Memoria minima necessaria para animacao, senao simplesmente sorteia um dos frames",¼
  43.                       #format: #integer,¼
  44.                      #default: 0 ],¼
  45.     #removeSpr: [ #comment: "Se deve nao mostrar nenhum sprite em caso de memoria curta",¼
  46.                       #format: #boolean,¼
  47.                      #default: false ],¼
  48.     #EmbaralhaInk: [ #comment: "Varia tambem a maneira de aplicar a imagem",¼
  49.                       #format: #integer,¼
  50.                      #default: 0 ]¼
  51.   ]
  52.   return p_list
  53. end
  54.  
  55. on beginSprite me
  56.   set spr = the spriteNum of me
  57.   inicializaAnima me
  58.   if prioridade < 0 then
  59.     set prioridade = 0
  60.   end if
  61. end
  62.  
  63. on inicializaAnima me
  64.   global myMemSize
  65.   set memPrim to the number of member memberPrim
  66.   set memQuantos to (the number of member memberUlt) - memPrim + 1
  67.   if myMemSize < memoria * 1024 * 1024 then
  68.     set sorteado = true
  69.     if removeSpr then
  70.       set the member of sprite spr to 1
  71.     else
  72.       set the member of sprite spr to member (memPrim + random(memQuantos) - 1)
  73.     end if
  74.   else 
  75.     set sorteado = false
  76.   end if
  77.   set proxEspera = random(espera)
  78.   put 0 into fotoAtual
  79.   set ultimaTroca = 0
  80.   if delta > 0 then set the visibility of sprite spr to false
  81.   
  82. end
  83.  
  84. on cleanSprite me
  85.   puppetSprite (the spriteNum of me),false
  86.   set the visibility of sprite spr to true
  87. end 
  88.  
  89. on idleSprite me
  90.   if delta = 0 and sorteado then return
  91.   if not the visibility of sprite spr and delta = 0 then return
  92.   global gMustUpdate
  93.   if ultimaTroca = 0 then set ultimaTroca = the timer
  94.   
  95.   set tmp = the timer - ultimaTroca
  96.   if delta > 0 and tmp > delta then
  97.     set ultimaTroca = the timer
  98.     set the visibility of sprite spr to true
  99.     set delta = 0
  100.     set tmp = 0
  101.     set gMustUpdate to true
  102.   end if
  103.   
  104.   if sorteado then return
  105.   
  106.   -- Testa se ja e' hora de trocar figura
  107.   if tempoAleatorio then
  108.     if tmp > proxEspera then
  109.       set tmp = true
  110.       set proxEspera = random(espera)
  111.     else
  112.       set tmp = false
  113.     end if
  114.   else
  115.     if tmp > espera then
  116.       set tmp = true
  117.     else
  118.       set tmp = false
  119.     end if
  120.   end if
  121.   
  122.   -- Troca, se ja' for hora e se nao for em area critica
  123.   global gCritico
  124.   if tmp and prioridade >= gCritico then
  125.     
  126.     -- Descobre qual a proxima figura a trocar
  127.     if (aleatorio) then
  128.       set tmp = random(memQuantos - 1) - 1
  129.       if tmp >= fotoAtual then set tmp = 1 + tmp
  130.       set fotoAtual = tmp 
  131.     else
  132.       set fotoAtual = fotoAtual + 1 
  133.       if fotoAtual >= memQuantos then set fotoAtual = 0 
  134.     end if
  135.     
  136.     -- Muda figura e updateStage
  137.     set the member of sprite (the spriteNum of me) to memPrim + fotoAtual
  138.     if fotoAtual < embaralhaInk then 
  139.       if random(2) = 1 then
  140.         set the ink of sprite (the spriteNum of me) to 3
  141.       else
  142.         set the ink of sprite (the spriteNum of me) to 36
  143.       end if
  144.     else if embaralhaInk > 0 then
  145.       set the ink of sprite (the spriteNum of me) to 36
  146.     end if
  147.     set gMustUpdate to true
  148.     set ultimaTroca = the timer 
  149.   end if
  150. end